﻿using CSW.Framework.Common.Binding.Events;

namespace CSW.Framework.Common.Binding
{
    /// <summary>
    /// UnboundProperty
    /// </summary>
    /// <typeparam name="T">The value type.</typeparam>
    public class UnboundProperty<T>
    {
        /// <summary>
        /// Occurs when the property has changed.
        /// </summary>
        public event TypedPropertyChangedEventHandler<T> PropertyChanged;

        private T m_Value;

        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>The value.</value>
        public T Value
        {
            get { return m_Value; }
            set
            {
                T oldValue = m_Value;
                m_Value = value;
                SendPropertyChanged(oldValue, m_Value);
            }
        }

        private void SendPropertyChanged(T oldValue, T newValue)
        {
            TypedPropertyChangedEventHandler<T> propertyChanged = PropertyChanged;
            if (propertyChanged != null)
                propertyChanged(this, new TypedPropertyChangedEventArgs<T>(oldValue, newValue));
        }
    }
}
